import 'package:flutter/material.dart';

class NotificationDialog {
  // ئۇقتۇرۇش كۆزنىكىنى كۆرسىتىش
  static void show(BuildContext context) {
    // تاسادىپىي ئانىماتسىيە تىپىنى تاللاش
    final animationType = DateTime.now().millisecondsSinceEpoch % 5;
    
    showGeneralDialog(
      context: context,
      barrierDismissible: true,
      barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
      barrierColor: Colors.black54,
      transitionDuration: const Duration(milliseconds: 400),
      pageBuilder: (context, animation1, animation2) => Container(),
      transitionBuilder: (context, animation1, animation2, child) {
        // ئانىماتسىيەنىڭ شەكلى ۋە يۆنىلىشى
        Curve curve;
        Animation<double> scaleAnimation;
        Animation<double> rotateAnimation;
        Animation<Offset> slideAnimation;
        
        // ھەر خىل ئانىماتسىيە تۈرلىرى
        switch (animationType) {
          case 0: // تۆۋەندىن يۇقىرىغا سىيرىلىش + چوڭىيىش
            curve = Curves.elasticOut;
            scaleAnimation = Tween<double>(begin: 0.6, end: 1.0)
                .animate(CurvedAnimation(parent: animation1, curve: curve));
            rotateAnimation = const AlwaysStoppedAnimation(0);
            slideAnimation = Tween<Offset>(begin: const Offset(0.0, 0.3), end: Offset.zero)
                .animate(CurvedAnimation(parent: animation1, curve: curve));
            break;
            
          case 1: // ئايلىنىش + سولغۇچ
            curve = Curves.easeOutBack;
            scaleAnimation = Tween<double>(begin: 0.8, end: 1.0)
                .animate(CurvedAnimation(parent: animation1, curve: curve));
            rotateAnimation = Tween<double>(begin: -0.1, end: 0.0)
                .animate(CurvedAnimation(parent: animation1, curve: curve));
            slideAnimation = const AlwaysStoppedAnimation(Offset.zero);
            break;
            
          case 2: // ئوڭدىن سولغا سىيرىلىش
            curve = Curves.fastOutSlowIn;
            scaleAnimation = Tween<double>(begin: 0.9, end: 1.0)
                .animate(CurvedAnimation(parent: animation1, curve: curve));
            rotateAnimation = const AlwaysStoppedAnimation(0);
            slideAnimation = Tween<Offset>(begin: const Offset(0.5, 0.0), end: Offset.zero)
                .animate(CurvedAnimation(parent: animation1, curve: curve));
            break;
            
          case 3: // سەكرەش ئانىماتسىيەسى
            curve = Curves.bounceOut;
            scaleAnimation = Tween<double>(begin: 0.7, end: 1.0)
                .animate(CurvedAnimation(parent: animation1, curve: curve));
            rotateAnimation = const AlwaysStoppedAnimation(0);
            slideAnimation = Tween<Offset>(begin: const Offset(0.0, -0.3), end: Offset.zero)
                .animate(CurvedAnimation(parent: animation1, curve: curve));
            break;
            
          default: // ھەر تەرەپتىن كىچىكلەش
            curve = Curves.easeInOutCirc;
            scaleAnimation = Tween<double>(begin: 1.5, end: 1.0)
                .animate(CurvedAnimation(parent: animation1, curve: curve));
            rotateAnimation = const AlwaysStoppedAnimation(0);
            slideAnimation = const AlwaysStoppedAnimation(Offset.zero);
        }
        
        return FadeTransition(
          opacity: Tween<double>(begin: 0.0, end: 1.0)
              .animate(CurvedAnimation(parent: animation1, curve: curve)),
          child: SlideTransition(
            position: slideAnimation,
            child: RotationTransition(
              turns: rotateAnimation,
              child: ScaleTransition(
                scale: scaleAnimation,
                child: Dialog(
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(16),
                  ),
                  child: AnimatedContainer(
                    duration: const Duration(milliseconds: 300),
                    curve: Curves.easeInOut,
                    width: 400,
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        Container(
                          padding: const EdgeInsets.all(16),
                          decoration: BoxDecoration(
                            color: _getHeaderColor(animationType), // ھەر قېتىم ئوخشىمىغان رەڭ
                            borderRadius: const BorderRadius.only(
                              topLeft: Radius.circular(16),
                              topRight: Radius.circular(16),
                            ),
                          ),
                          child: Row(
                            children: [
                              TweenAnimationBuilder<double>(
                                tween: Tween<double>(begin: 0.0, end: 1.0),
                                duration: const Duration(milliseconds: 400),
                                builder: (context, value, child) {
                                  return Transform.rotate(
                                    angle: value * 2 * 3.14,
                                    child: child,
                                  );
                                },
                                child: const Icon(Icons.notifications, color: Colors.white),
                              ),
                              const SizedBox(width: 8),
                              const Text(
                                'ئۇقتۇرۇشلار',
                                style: TextStyle(
                                  color: Colors.white,
                                  fontSize: 18,
                                  fontWeight: FontWeight.bold,
                                ),
                              ),
                            ],
                          ),
                        ),
                        ListView(
                          shrinkWrap: true,
                          padding: const EdgeInsets.all(16),
                          children: [
                            _buildNotificationItem(
                              'يېڭى مال كىرگۈزۈلدى',
                              'ThinkPad X1 Carbon دىن 10 دانە كىرگۈزۈلدى',
                              '5 مىنۇت بۇرۇن',
                              Colors.blue,
                              0,
                            ),
                            const Divider(),
                            _buildNotificationItem(
                              'مال تۈگەپ قالدى',
                              'iPhone 14 Pro نىڭ ئامباردىكى سانى 3 دانە قالدى',
                              '15 مىنۇت بۇرۇن',
                              Colors.red,
                              1,
                            ),
                            const Divider(),
                            _buildNotificationItem(
                              'يېڭى سودا',
                              'HP LaserJet Pro دىن 2 دانە سېتىلدى',
                              '30 مىنۇت بۇرۇن',
                              Colors.green,
                              2,
                            ),
                          ],
                        ),
                        Padding(
                          padding: const EdgeInsets.all(16),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.end,
                            children: [
                              TextButton(
                                onPressed: () {
                                  Navigator.of(context).pop();
                                },
                                child: const Text('تاقاش'),
                              ),
                              const SizedBox(width: 8),
                              ElevatedButton(
                                style: ElevatedButton.styleFrom(
                                  backgroundColor: _getHeaderColor(animationType),
                                  padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
                                  shape: RoundedRectangleBorder(
                                    borderRadius: BorderRadius.circular(8),
                                  ),
                                ),
                                onPressed: () {
                                  // ھەممىنى ئوقۇلدى قىلىش
                                  Navigator.of(context).pop();
                                },
                                child: const Text('ھەممىنى ئوقۇلدى'),
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
            ),
          ),
        );
      },
    );
  }

  // ئۇقتۇرۇش تۈرى
  static Widget _buildNotificationItem(
    String title,
    String message,
    String time,
    Color color,
    int index,
  ) {
    return AnimatedOpacity(
      duration: Duration(milliseconds: 500 + index * 200),
      opacity: 1.0,
      child: AnimatedPadding(
        duration: Duration(milliseconds: 500 + index * 100),
        padding: EdgeInsets.only(right: 0, left: 0),
        child: ListTile(
          contentPadding: EdgeInsets.zero,
          leading: TweenAnimationBuilder<double>(
            tween: Tween<double>(begin: 0.5, end: 1.0),
            duration: Duration(milliseconds: 500 + index * 300),
            curve: Curves.elasticOut,
            builder: (context, value, child) {
              return Transform.scale(
                scale: value,
                child: child,
              );
            },
            child: Container(
              width: 40,
              height: 40,
              decoration: BoxDecoration(
                color: color.withOpacity(0.1),
                shape: BoxShape.circle,
              ),
              child: Icon(Icons.notifications, color: color),
            ),
          ),
          title: Text(
            title,
            style: const TextStyle(
              fontWeight: FontWeight.bold,
            ),
          ),
          subtitle: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              const SizedBox(height: 4),
              Text(message),
              const SizedBox(height: 4),
              Text(
                time,
                style: TextStyle(
                  color: Colors.grey[600],
                  fontSize: 12,
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
  
  // ھەر خىل باش قىسىم رەڭلىرى
  static Color _getHeaderColor(int animationType) {
    switch (animationType) {
      case 0:
        return const Color(0xFF2C3E67); // كۆك
      case 1:
        return const Color(0xFF673AB7); // بىنەپشە
      case 2:
        return const Color(0xFF009688); // يېشىل
      case 3:
        return const Color(0xFFE91E63); // قىزىل
      default:
        return const Color(0xFF2196F3); // كۆك
    }
  }
} 